package org.msb.accentis.utils;

import static java.text.DateFormat.SHORT;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;

public class DateUtils {

	private static ThreadLocal<DateFormat> shortDateFormats = new ThreadLocal<DateFormat>() {
		@Override
		protected DateFormat initialValue() {
			return DateFormat.getDateInstance(SHORT);
		}
	};
	
	public static String format(Date date) {
		if (null == date)
			return null;
		
		return shortDateFormats.get().format(date);
	}
	
	public static Date parse(String date) throws ParseException {
		if (null == date)
			return null;
		
		return shortDateFormats.get().parse(date);
	}
}
